IndexedDB is a client-side, NoSQL database that allows web applications to store large amounts of structured data inside a user's browser. It is useful for applications that need offline functionality, fast data retrieval, or persistent storage beyond a single session.
It provides:
localStorage, which has a size limit, IndexedDB can store large blobs and files.
When the database version changes, the onupgradeneeded event is triggered. We use it to create an object store.
users): Stores user data.id): Auto-increments for each entry.name): Enables searching users by name.
readwrite mode is used since we are modifying data.
id.
id.| Feature | localStorage | sessionStorage | IndexedDB |
|---|---|---|---|
| Storage Limit | ~5MB | ~5MB | Large (hundreds of MBs) |
| Data Type | Strings | Strings | Objects, Blobs, Files |
| Indexed Search | ❌ | ❌ | ✅ |
| Transactions | ❌ | ❌ | ✅ |
| Asynchronous | ❌ | ❌ | ✅ |
IndexedDB is best for structured data, whereas localStorage is good for small key-value pairs.
Let me know if you need further explanations! 🚀